package com.gsnd.briuppts.exception;

import com.gsnd.briuppts.result.Response;
import com.gsnd.briuppts.result.ResponseCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
// @RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Response handleException(Exception e) {
        Response result = null;
        if (e instanceof PtsException) {
            result = Response.error(((PtsException) e).getResponseCode(),"pts异常");
        } else {
            result = Response.error(ResponseCode.ERROR,"服务器内部错误");
        }
        return result;
    }
}
